

// Computer vision libraries: -----------------------------------//
#include "OpenCV10/cv.h"



#include "imageuc.h"

#include <iostream>
#include <cv.h>
#include <highgui.h>
#include <string.h>

using namespace std;
void buildName(const char* pattern,int indexCurrentImage,int numberZeros,const char* extencao, string& ret )
{	
	char nomeArquivo [1024];
	char patternString [64];
	string mIndexString, mNameCurrentImage;
	sprintf_s(patternString,63,"%%s%%0%d.f%%s",numberZeros);
	sprintf_s(nomeArquivo,patternString,pattern,(float)indexCurrentImage,extencao);
	ret = nomeArquivo;
}


int main()
{
		
		
	CvCapture* file = cvCaptureFromAVI("..\\videoXYZ.avi");	// video de entrada

	char* nameFile = "..\\videoXYZ_"; // padrao da sequencia de videos de saida
	double frame = 0; // frame inicial	
	string name;	
	
	while(true)
	{	
		cvSetCaptureProperty(file, CV_CAP_PROP_POS_FRAMES, frame);
		IplImage* image = cvQueryFrame(file);
		if (image == NULL)		
			break;

		buildName(nameFile,(int)frame,5,".bmp",name);

		cvSaveImage(name.c_str(),image);
		frame++;

		printf("%lf\n",frame);
	}
	
	cvReleaseCapture(&file);
	return 0;
}